import { defineStore } from 'pinia'
import { ref } from 'vue'
import { DialogQueue } from '@/utils/dialogQueue'

export const useInfoDialogStore = defineStore('info', () => {
  // 状态
  const dialogQueue = new DialogQueue()
  const currentDialog = ref(null)

  // 动作
  function show(titleText, messageText) {
    return dialogQueue.show({
      onLoaded: () => {
        currentDialog.value = {
          title: titleText,
          message: messageText
        }
      }
    })
  }

  function hide() {
    dialogQueue.hide()
  }

  return {
    // 状态
    isVisible: dialogQueue.isVisible,
    title: () => currentDialog.value?.title || '',
    message: () => currentDialog.value?.message || '',
    // 动作
    show,
    hide,
    getQueueLength: dialogQueue.getQueueLength.bind(dialogQueue),
    clearQueue: dialogQueue.clearQueue.bind(dialogQueue)
  }
}) 